package ut.servlet.member;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
public class PickFreeResponse extends HttpServlet{
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		// 取得並驗證使用者輸入資訊
		long id;
		int translator;
		if(request.getParameter("id") == null || request.getParameter("translator") == null){
			return;
		}else{
			try{
				id = Long.parseLong(request.getParameter("id"));
				translator = Integer.parseInt(request.getParameter("translator"));
			}catch(NumberFormatException e){
				return;
			}
		}
		// 確認使用者已經完成信箱驗證
		ut.data.User user = (ut.data.User)request.getSession().getAttribute("user");
		if(user.verify == 0){
			return;
		}
		// 更新資料庫
		response.setIntHeader("result", ut.data.FreeTask.pickResponse(id, user.id, translator)); // -1: 系統錯誤、0: 失敗、1: 成功
	}
}